// pages/user/myOrderDetail/myOrderDetail.js
var app=getApp();
var sureOrder=false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_id:'',//订单id
    orderDetailshow:'',//订单详细信息
    status: '',//审核态状态 1待审核2审核通过3审核失败
    realnameShow: false,//弹窗显示
    authInfo: { 'status_name': '待认证', status: '' }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      order_id: options.order_id
    })
    that.getRealnameInfo();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    // that.getAuthInfo();//获取用户认证状态
    wx.showLoading({
      title: '加载中...',
    })
    that.getOrderDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  //跳转地址列表
  shoppingDetail: function (e) {
    var that = this;
    var equipments_id = e.currentTarget.dataset.equipments_id;
    wx.navigateTo({
      url: '../../shopping/goodsDetail/goodsDetail?equipments_id=' + equipments_id,
    })
  },
  //去支付
  goPayfor(e) {
    var that = this;
    var order_id = that.data.order_id;
    wx.navigateTo({
      url: '../../shopping/payment/payment?order_id=' + order_id,
    })
  },
  //预约安装
  appointment(e) {
    var that = this;
    var order_id = that.data.order_id;
    var status = that.data.authInfo.status;
    if (status == 2) {
      that.setData({
        realnameShow: false
      })
      wx.navigateTo({
        url: '../appointment/appointment?order_id=' + order_id,
      })
    } else {
      that.setData({
        realnameShow: true,
        order_id: order_id
      })
    }

  },
  // 关闭弹窗
  cancelModal: function () {
    var that = this;
    that.setData({
      realnameShow: false,
      order_id: ''
    })
  },
 
  // 继续预约
  goAppointment: function () {
    var that = this;
    var order_id = that.data.order_id;
    wx.navigateTo({
      url: '../appointment/appointment?order_id=' + order_id,
    })
  },
  //催单
  deliver:function(e){
    var that = this;
    var order_id = that.data.order_id;
    app.showModal('','该功能近期即将上线,敬请期待!');
    
  },
  //取消订单
  Cancellation(){
    var that = this;
    var order_id = that.data.order_id;
    wx.showModal({
      title: '提示',
      content: '是否删除该订单',
      confirmColor: '#c80000',
      success: function (res) {
        if (res.confirm) {
          app.ajax({
            url: 'User/Order/cancelOrder',
            method: 'POST',
            data: {
              order_id: order_id
            },
            success: function (res) {
              app.showToast(res.data.message);
              var timer = setTimeout(function(){
                wx.navigateBack({
                  delta:1
                })
              },1000);
            }
          })

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 提醒发货
  remindOrder: function () {
    app.showToast("该功能正在开发中，敬请期待");
  },
  // 查看物流
  lookLogistics: function (e) {
    var that = this;
    var order_id = that.data.order_id;
    wx.navigateTo({
      url: '../logistics/logistics?order_id=' + order_id,
    })
  },
  // 确认收货
  confirmReceipt: function () {
    var that = this;
    var order_id = that.data.order_id;
    wx.showModal({
      title: '提示',
      content: '是否确认收货',
      confirmColor: '#c80000',
      success: function (res) {
        // if (sureOrder) {
        //   return false
        // }
        sureOrder = true;
        if (res.confirm) {
          app.ajax({
            url: 'User/Order/collectGoods',
            data: {
              order_id: order_id
            },
            success: function (res) {
              if (res.data.code == 1000) {
                app.showToast(res.data.message + ',请前去预约安装');
                var timer = setTimeout(function () {
                  // var tables = that.data.tables;
                  var tables = 3;
                  that.setData({
                    tables: tables
                  })
                  var new_type = '', pin_show = '';
                  if (tables == 0) {
                    new_type = '';
                  } else if (tables == 1) {
                    new_type = 1;
                  } else if (tables == 2) {
                    new_type = 2;
                  } else if (tables == 3) {
                    new_type = 3;
                  } else if (tables == 4) {
                    new_type = 4;
                  } else if (tables == 5) {
                    pin_show = 1;
                    new_type = 4;
                  } else if (tables == 6) {
                    new_type = 6;
                  }
                  that.getOrderDetail();
                  // that.getMyRentalLists(new_type, pin_show);
                }, 1000)
              } else {
                app.showToast(res.data.message);
              }
              sureOrder = false;
            }
          })

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  //跳转评价
  evaluate(e) {
    var that = this;
    var order_id = that.data.order_id;
    wx.navigateTo({
      url: '../goEvaluate/goEvaluate?order_id=' + order_id,
    })
  },
  //获取订单详情
  getOrderDetail(){
    var that=this;
    var order_id = that.data.order_id;
    app.ajax({
      url: 'User/Order/getOrderDetail',
      method: "POST",
      data: { order_id: order_id},
      success: function (res) {
        wx.hideLoading();
        if (res.data.code=1000){
            that.setData({
              orderDetailshow:res.data.data,
            })
        }
      }

      })
  },
  /*//获取是否实名
  getAuthInfo() {
    var that = this;
    var order_id = that.data.order_id;
    app.ajax({
      url: 'User/User/getAuthInfo',
      method: "POST",
      data: { },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code == 1000) {
          that.setData({
            status: res.data.data.status
          })
        } else if (res.data.code == -1003) {
          that.setData({
            status: ''
          })
        }
      }

    })
  },*/
  // 售后记录详情
  goDetail: function (e) {
    wx.navigateTo({
      url: '../afterSaleDetail/afterSaleDetail?detail=' + e.currentTarget.dataset.work_order_id,
    })
  },
  //设备激活
  active:function(){
    var that = this;
    wx.navigateTo({
      url: '../../activeDevice/activeDevice?order_id=' + that.data.order_id,
    })
  },
  // 订单投诉
  goComplaint: function () {
    var that = this;
    var order_id = that.data.order_id;
    wx.navigateTo({
      url: '../../complaint/complaint?comType=1&order_id=' + order_id,
    })

  },
  //图片加载错误
  Order_error(e) {
    var that = this, orderDetailshow = that.data.orderDetailshow, nowIndex = e.currentTarget.dataset.nowindex;
    orderDetailshow.main_pic = '../../../images/none.png'
    that.setData({
      orderDetailshow: orderDetailshow
    })
  },
  //跳转我的认证
  goRealname() {
    var that = this;
    if (that.data.authInfo.status == -2) {
      wx.navigateTo({ //../../shopping/uploadDocuments/uploadDocuments
        url: '../../shopping/uploadDocuments/uploadDocuments',
      })
    } else if (that.data.authInfo.status == -3) {
      wx.navigateTo({
        url: '../../shopping/faceRecognition/faceRecognition',
      })
    } else if (that.data.authInfo.status == 2 || that.data.authInfo.status == 1) {
      wx.navigateTo({
        url: '../../myCertification/myCertification',
      })
    } else {
      wx.navigateTo({
        url: '../../shopping/realName/realName',
      })
    }

  },
  //获取用户认证信息
  getRealnameInfo() {
    var that = this;
    app.ajax({
      url: "User/Realname/getAuthInfo",
      data: {},
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            authInfo: res.data.data
          })
        } else {
          that.setData({
            authInfo: { 'status_name': '待认证', 'status': '' }
          })
        }
      }
    })
  }
})